package com.study.thread;

/**
 * @author geticsen
 */
public class ThreadObjectLock {
    private static final Object obj = new Object();
    static class ThreadA implements Runnable {
        @Override
        public void run() {
            synchronized(obj){
                for (int i = 0; i < 50; i++) {
                    System.out.println("i1 = " + i);
                }
            }

        }
    }

    static class ThreadB implements Runnable {
        @Override
        public void run() {
            synchronized (obj){
                for (int i = 0; i < 50; i++) {
                    System.out.println("i2 = " + i);
                }
            }

        }
    }

    public static void main(String[] args) throws InterruptedException {
        new Thread(new ThreadA()).start();
        Thread.sleep(10);
        new Thread(new ThreadB()).start();

    }
}
